<?php 
require_once('kelas/record.php');

require_once('kelas/kategori.php');
require_once('kelas/produk.php');
require_once('kelas/transaksi.php');
require_once('kelas/kota.php');
require_once('kelas/rekening.php');
$objRecord = new record();

if(!isset($_SESSION['detail_cart'])){
    echo $objFungsi->redirect(BASEURL);
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo BASEURL; ?>css/isi.css">
<?php echo $objFungsi->buatJudul('Pengiriman dan Pembayaran',110); ?>
<div class="frame_table_order">
<table width="100%" cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse">

    <thead>
        <tr align="center" valign="middle" bgcolor="#CCCCCC">            <th>No</th>
            <th>Gambar</th>
            <th>Nama</th>
            <th>Harga</th>
            <th>Qty</th>
            <th>Subtotal</th>
            <th>Ubah</th>

        </tr>
    </thead>
    <tbody>
        <?php
        $total = 0;
        $dtS = $objTransaksi->detailTemp();
        if ($dtS['total'] == 0) {
            ?>
            <tr>
                <td colspan="7">(belum ada item)</td>

            </tr>
            <?php
        } else {
            $no=1;
            
            foreach ($dtS['result'] as $k=>$value){
                $hrg = $value['diskon']>0?($value['harga_jual']-($value['harga_jual']*($value['diskon']/100))):$value['harga_jual'];
                ?>
                <tr> 
                    <td><?php echo $no++;?></td>
                    <td><img style="width:50px;height:50px" src="<?php echo BASEURL.'produk/'.$value['gambar']; ?>"/></td>
                    <td>Nama</td>
                    <td style="text-align: right"><?php echo ($value['diskon']>0)?"<span style='text-decoration:line-through;color:red;font-size:small'>".number_format($value['harga_jual'],0,'.',',')."</span><br/>":"";echo number_format($hrg,0,'.',',')?></td>
                    <td>
                        <input disabled="disabled" value="<?php echo $value['jumlah_buy'];?>" class="text_box_50" name="buy[<?php echo (string)$k;?>]" />
                        <input value="<?php echo $value['id'];?>" type="hidden" class="text_box_50" name="id[<?php echo (string)$k;?>]" />
                    </td>
                    <td style="text-align: right"><?php $total +=$hrg*$value['jumlah_buy'] ;echo number_format($hrg*$value['jumlah_buy'],0,'.',','); ?></td>
                    <td><a class="button_2" href="<?php echo BASEURL.'?v=cart' ?>">Ubah</a></td>
                </tr>
                <?php
            }
        }
        ?>

    </tbody>
    <tfoot>
        <tr>
            <th colspan="6" style="text-align: right">Total: <input style="text-align:right" type="text" class="option" disabled="disabled" value="<?php echo "Rp. ".number_format( $total,0,'.',','); ?>" />
            </th>
            <th style="text-align: right"><a href="<?php BASEURL ?>index.php?v=cart" class="option">Kembali Ke Cart</a>
            </th>
            
        </tr>
        
    </tfoot>
</table>
</div>
<form method="POST" <?php if($dtS['total'] == 0){}else{ ?> action="<?php echo BASEURL.'proses/pemesanan.php?on=finish'; ?>" <?php } ?>>
    <div style="float:left;width:60%">
        <br>
    <?php echo $objFungsi->buatJudul('Informasi Alamat Pengiriman',60); ?>
    <table>
        <tr><td>Nama Penerima</td><td>
            <input required="required" class="text_box_3" name="nama_penerima" value="<?php echo isset($_SESSION['userlogin'])?$_SESSION['userlogin']['nama']:''; ?>"  /></td></tr>
        <tr><td>Alamat</td><td><textarea  required="required" name="alamat" class="text_box_3" ><?php echo isset($_SESSION['userlogin'])?$_SESSION['userlogin']['alamat']:''; ?></textarea></td></tr>
        <tr><td>Telepon</td><td><input  required="required" name="telepon" class="text_box_3" value="<?php echo isset($_SESSION['userlogin'])?$_SESSION['userlogin']['telepon']:''; ?>" /></td></tr>
        <tr><td>E-mail</td><td><input name="email"  required="required" class="text_box_3" value="<?php echo isset($_SESSION['userlogin'])?$_SESSION['userlogin']['email']:''; ?>" /></td></tr>
        <tr><td>Pesan Tambahan</td><td>
            <textarea name="pesan_tambahan" class="text_box_3"></textarea>
        </td></tr>
        <tr><td>Kota</td><td>
            <select class="text_box_3" name="ongkir"  required="required">
<?php echo ($objKota->getCombo()); ?>
            </select>
        </td></tr>
    </table>
    </div>
    <div  style="float:right;width:40%">
<br>
<?php echo $objFungsi->buatJudul('Pembayaran',45) ?>
<table>
        <tr>
<th>Pilih Nomor Rekening:</th><td>
<select name="rekening" class="text_box_3" required="required">
    <?php echo $objRekening->getCombo(); ?>
</select>
</td>
        </tr>

    </table>
    <span><input type="submit" value="Selesai, Lakukan Pemesanan"></span>
    <span><input type="reset" value="Reset"></span>
    </div>
</form>